package com.example.firststory;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.paypal.android.MEP.CheckoutButton;
import com.paypal.android.MEP.PayPal;
import com.paypal.android.MEP.PayPalInvoiceData;
import com.paypal.android.MEP.PayPalPayment;
import com.paypal.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;


//{"scope":"https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/services/invoicing https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*","access_token":"A015ZA-quRb472Wr-GJcePw0fHVs5jVNJX-.Pjp4MTJ-rXo","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":28800}

public class Pago extends Activity {

	private boolean _paypalLibraryInit;
	private CheckoutButton pagar;
	private BigDecimal iva = new BigDecimal("0.21");
	private BigDecimal precio;
	private Button paraPayPal;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pay_pal);
		
		getReferencias();
		//initLibrary();
	}
	
	public void getReferencias(){
		
		paraPayPal = (Button) findViewById(R.id.btnPP);
		
	}

	// snippets de PayPal

	
//	public void createPayment(){
//		Map<String, String> sdkConfig = new HashMap<String, String>();
//		sdkConfig.put("mode", "sandbox");
//
//		String accessToken = "Bearer A015ZA-quRb472Wr-GJcePw0fHVs5jVNJX-.Pjp4MTJ-rXo";
//		APIContext apiContext = new APIContext(accessToken);
//		apiContext.setConfigurationMap(sdkConfig);
//
//		Amount amount = new Amount();
//		amount.setCurrency("EUR");
//		amount.setTotal("12");
//
//		Transaction transaction = new Transaction();
//		transaction.setDescription("creating a payment");
//		transaction.setAmount(amount);
//
//		List<Transaction> transactions = new ArrayList<Transaction>();
//		transactions.add(transaction);
//
//		Payer payer = new Payer();
//		payer.setPaymentMethod("paypal");
//
//		Payment payment = new Payment();
//		payment.setIntent("sale");
//		payment.setPayer(payer);
//		payment.setTransactions(transactions);
//		RedirectUrls redirectUrls = new RedirectUrls();
//		redirectUrls.setCancelUrl("https://devtools-paypal.com/guide/pay_paypal?cancel=true");
//		redirectUrls.setReturnUrl("https://devtools-paypal.com/guide/pay_paypal?success=true");
//		payment.setRedirectUrls(redirectUrls);
//
//		Payment createdPayment = payment.create(apiContext);
//	}
//	public void initLibrary() {
//		PayPal pp = PayPal.getInstance();
//
//		if (pp == null) { // Test to see if the library is already initialized
//
//			// This main initialization call takes your Context, AppID, and
//			// target server
//			pp = PayPal.initWithAppID(this, "APP-80W284485P519543T",
//					PayPal.ENV_NONE);
//
//			// Required settings:
//
//			// Set the language for the library
//			pp.setLanguage("es_ES");
//
//			// Some Optional settings:
//
//			// Sets who pays any transaction fees. Possible values are:
//			// FEEPAYER_SENDER, FEEPAYER_PRIMARYRECEIVER, FEEPAYER_EACHRECEIVER,
//			// and FEEPAYER_SECONDARYONLY
//			pp.setFeesPayer(PayPal.FEEPAYER_EACHRECEIVER);
//
//			// true = transaction requires shipping
//			pp.setShippingEnabled(true);
//
//			_paypalLibraryInit = true;
//		}
//	}
//
//	private void showPayPalButton() {
//
//		// Generate the PayPal checkout button and save it for later use
//		PayPal pp = PayPal.getInstance();
//		pagar = pp.getCheckoutButton(this, PayPal.BUTTON_278x43,
//				CheckoutButton.TEXT_PAY);
//
//		// The OnClick listener for the checkout button
//		pagar.setOnClickListener((OnClickListener) this);
//
//		// Add the listener to the layout
//		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
//				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//		
//		params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//		params.bottomMargin = 10;
//		pagar.setLayoutParams(params);
//		pagar.setId(paraPayPal.getId());
//		
//		((RelativeLayout) findViewById(R.id.RelativeLayout01))
//				.addView(pagar);
//		((RelativeLayout) findViewById(R.id.RelativeLayout01))
//				.setGravity(Gravity.CENTER_HORIZONTAL);
//	}
//	
//	public void PayPalButtonClick(View arg0) {
//		// Create a basic PayPal payment
//		PayPalPayment payment = new PayPalPayment();
//
//		// Set the currency type
//		payment.setCurrencyType("EUR");
//
//		// Set the recipient for the payment (can be a phone number)
//		payment.setRecipient("ppalav_1285013097_biz@yahoo.com");
//
//		// Set the payment amount, excluding tax and shipping costs
//		payment.setSubtotal(precio);
//
//		// Set the payment type--his can be PAYMENT_TYPE_GOODS,
//		// PAYMENT_TYPE_SERVICE, PAYMENT_TYPE_PERSONAL, or PAYMENT_TYPE_NONE
//		payment.setPaymentType(PayPal.PAYMENT_TYPE_GOODS);
//
//		// PayPalInvoiceData can contain tax and shipping amounts, and an
//		// ArrayList of PayPalInvoiceItem that you can fill out.
//		// These are not required for any transaction.
//		PayPalInvoiceData invoice = new PayPalInvoiceData();
//
//		// Set the tax amount
//		invoice.setTax(iva);
//		}
}
